﻿// -------------------------------------------------------------------------
//    @FileName         :    NFCommLogicModule.cpp
//    @Author           :    xxxxx
//    @Date             :   xxxx-xx-xx
//    @Email			:    xxxxxxxxx@xxx.xxx
//    @Module           :    NFCommLogicPlugin
//
// -------------------------------------------------------------------------

#include "NFMMOCommonModule.h"

#include <NFLogicCommon/NFOperatingStatistcsMgr.h>

#include "NFComm/NFPluginModule/NFLogMgr.h"
#define OPERATING_STAT_TIMER 1

bool NFMMOCommonModule::Awake()
{
    auto &allServerType = NFGlobalSystem::Instance()->GetAllServerType();
    for (auto iter = allServerType.begin(); iter != allServerType.end(); iter++)
    {
        NF_SERVER_TYPE serverType = (NF_SERVER_TYPE) *iter;
        RegisterAppTask(serverType, APP_INIT_DESC_STORE_LOAD, GetServerName(serverType) + " Load Desc Store", APP_INIT_TASK_GROUP_SERVER_LOAD_DESC_STORE);
        Subscribe(serverType, NFrame::NF_EVENT_SERVER_TASK_GROUP_FINISH, NFrame::NF_EVENT_SERVER_TYPE, APP_INIT_TASK_GROUP_SERVER_LOAD_DESC_STORE,
          __FUNCTION__);
    }

    NFOperatingStatistcsMgr::Instance()->Initialize(60, true);
    SetTimer(OPERATING_STAT_TIMER, 60000);
    return true;
}

int NFMMOCommonModule::OnExecute(uint32_t serverType, uint32_t nEventID, uint32_t bySrcType, uint64_t nSrcID, const google::protobuf::Message* pMessage)
{
    if (nEventID == NFrame::NF_EVENT_SERVER_TASK_GROUP_FINISH && bySrcType == NFrame::NF_EVENT_SERVER_TYPE &&
        nSrcID == APP_INIT_TASK_GROUP_SERVER_LOAD_DESC_STORE)
    {
    }
    return 0;
}

int NFMMOCommonModule::OnTimer(uint32_t nTimerID)
{
    if (nTimerID == OPERATING_STAT_TIMER)
    {
        NFOperatingStatistcsMgr::Instance()->Tick();
    }
    return 0;
}
